#!/bin/bash
# A2A多智能体系统启动脚本

echo "🚀 启动A2A多智能体旅行规划系统..."

# 检查uv是否安装
if ! command -v uv &> /dev/null; then
    echo "❌ 错误: 请先安装uv (https://docs.astral.sh/uv/getting-started/installation/)"
    exit 1
fi

# 进入项目目录
cd "$(dirname "$0")"

echo "📦 安装依赖..."
uv sync

echo "🤖 启动Agent服务..."

# 启动各个Agent (后台运行)
echo "启动CoordinatorAgent (端口7006)..."
uv run python coordinator_agent.py > coordinator.log 2>&1 &
COORDINATOR_PID=$!

echo "启动BudgetAgent (端口7007)..."
uv run python budget_agent.py > budget.log 2>&1 &
BUDGET_PID=$!

echo "启动TravelAgent (端口7004)..."
uv run python travel_agent.py > travel.log 2>&1 &
TRAVEL_PID=$!

echo "启动WeatherAgent (端口7003)..."
uv run python intelligent_weather_agent.py > weather.log 2>&1 &
WEATHER_PID=$!

echo "启动RestaurantAgent (端口7005)..."
uv run python restaurant_agent.py > restaurant.log 2>&1 &
RESTAURANT_PID=$!

echo "启动Web后端 (端口8000)..."
cd web_interface/backend
uv run python web_backend.py > ../../web.log 2>&1 &
WEB_PID=$!
cd ../..

# 等待服务启动
echo "⏳ 等待服务启动..."
sleep 5

echo "✅ 系统启动完成!"
echo ""
echo "📍 访问地址:"
echo "   主界面: http://localhost:3000"
echo "   数据流可视化: http://localhost:8000/data_flow_visualization.html"
echo ""
echo "📋 进程ID:"
echo "   CoordinatorAgent: $COORDINATOR_PID"
echo "   BudgetAgent: $BUDGET_PID"
echo "   TravelAgent: $TRAVEL_PID"
echo "   WeatherAgent: $WEATHER_PID"
echo "   RestaurantAgent: $RESTAURANT_PID"
echo "   Web后端: $WEB_PID"
echo ""
echo "🛑 停止系统: kill $COORDINATOR_PID $BUDGET_PID $TRAVEL_PID $WEATHER_PID $RESTAURANT_PID $WEB_PID"
echo "📜 查看日志: tail -f *.log"